// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import axios from 'axios'
import cookies from 'js-cookie'
import VueResource from 'vue-resource'
import router from './router'
import store from './store/store'
import moment from 'moment'
import $ from 'jquery'
import vis from 'vis'
import Vuelidate from 'vuelidate'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'metismenu/dist/metisMenu.min.css'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap/dist/js/bootstrap.min'
import 'bootstrap/dist/js/bootstrap'
import 'sweetalert/dist/sweetalert.css'
import md5 from 'js-md5'
import qs from 'qs'
import when from 'when'
import swal from 'sweetalert'
import JsEncrypt from 'jsencrypt/bin/jsencrypt'
import '../node_modules/bootstrap-select/dist/js/bootstrap-select.min'
import '../node_modules/bootstrap-select/dist/css/bootstrap-select.min.css'
import './assets/css/iconfont/iconfont.css'
import './assets/css/global.less'
//自定义组件
import selectInput from './components/myComponents/selectInput'
import flowInput from './components/myComponents/flowInput'
import flowInputBps from './components/myComponents/flowInputBps'
import singleInput from './components/myComponents/singleInput'
import ipInput from './components/myComponents/ipInput'
import priority from './components/myComponents/priority'
// import 'jquery-ui'
import 'jquery-ui/external/jquery-1.11.0/jquery';
// import './assets/css/jquery-ui.min';
// import './assets/css/jquery.jsPlumb-1.6.2-min.js';
// import 'jquery-ui/dist/js/jquery-ui.min'
import jsPlumb from 'jsplumb';
import 'babel-polyfill';
/*引入公共样式*/
import config from './../static/js/config';
import '../node_modules/font-awesome/css/font-awesome.css';
import './../static/js/metisMenu.min';
import './../static/js/metisMenu';
import echarts from 'echarts';
import loginObj from './../static/js/loginValidate';
// 引入自定义指令
import './components/myComponents/directive.js';
// import 'highcharts'
// import 'highcharts/modules/sankey'
// import 'highcharts/modules/dependency-wheel'
//右键菜单
import Contextmenu from "vue-contextmenujs";

//注册自定义组件
Vue.component('selectInput',selectInput);
Vue.component('flowInput',flowInput);
Vue.component('flowBps',flowInputBps);
Vue.component('singleInput',singleInput);
Vue.component('ipInput',ipInput);
Vue.component('priority',priority);

Vue.prototype.$echarts = echarts;
// Vue.prototype.$highCharts = highCharts;
Vue.prototype.$jsPlumb = jsPlumb.jsPlumb;
Vue.prototype.$md5 = md5;
Vue.prototype.$qs = qs;
Vue.prototype.$vis = vis;
Vue.prototype.$jsEncrypt = JsEncrypt;
Vue.prototype.$cookies = cookies;
Vue.prototype.$swal = swal;
Vue.prototype.$when = when;
Vue.prototype.$jq = $;
Vue.prototype.$moment = moment;
axios.defaults.withCredentials = true;
//解决跨域
// axios.defaults.headers.post['Content-Type'] = 'text/plain'
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// axios.defaults.headers.post['Content-Type'] = 'application/json';
// 添加请求拦截器
axios.interceptors.request.use(config => {
  // if(!cookies.get("advertiser_id")){
  //   router.push("/login")
  // }
  // 在发送请求之前做些什么
  // store.commit('showLoading')
  return config;
}, error => {
  // 对请求错误做些什么
  return Promise.reject(error);
});
// 添加响应拦截器
axios.interceptors.response.use(response => {
  // 对响应数据做点什么
  store.commit('hideLoading');
  if (response.data.code ==='03') {
    router.push("/login");
    localStorage.setItem("activeMenu", 1);//重置为首页
    return;
  }
  return response;
}, error => {
  // 对响应错误做点什么
  store.commit('hideLoading')
  return Promise.reject(error);
});
Vue.prototype.$axios = axios;
Vue.config.productionTip = false;
Vue.use(VueResource);
Vue.use(ElementUI);
Vue.use(Contextmenu);
Vue.use(Vuelidate);
Vue.http.options.xhr = {withCredentials: true};
/* eslint-disable no-new */
//登录验证
let app = new Vue({
  el: '#app',
  store,
  router,
  components: {App},
  template: '<App/>',
});

// 路由跳转前的钩子
router.beforeEach((to, from, next) => {
  next();
});

// 路由跳转后的钩子
router.afterEach((to,from,next) => {
  store.commit('hideLoading');
  // next();
});

